<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/alllayui/layui/css/layui.css}" media="all">
    <script th:src="@{/alllayui/layui/layui.js}" charset="utf-8"></script>
    <script th:src="@{/system/js/jquery.min.js}" charset="utf-8"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>修改Member</legend>
</fieldset>

<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">会员ID</label>
        <div class="layui-input-block">
            <input type="text" readonly="readonly" name='mid' th:value='${member.mid}' lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">会员类型</label>
        <div class="layui-input-block">
            <input type="text" name='category' th:value='${member.category}' lay-verify="required" lay-reqtext="会员类型为必填项" placeholder="请输入会员类型"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">会员折扣</label>
        <div class="layui-input-block">
            <input type="text" name='rate' th:value='${member.rate}' lay-verify="required" lay-reqtext="会员折扣为必填项" placeholder="请输入会员折扣"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="subBtn">提交</button>
        </div>
    </div>
</form>
<script>
    layui.use(['jquery', 'form', 'laydate'], function () {
        var thisIndex = parent.layer.getFrameIndex(window.name);
        var form = layui.form
            , layer = layui.layer
            , $ = layui.$;
        var laydate = layui.laydate;

        var parentLayer = parent.layer;
        var pWindow = parent;
        form.on('submit(subBtn)', function (data) {
            let data2Send = data.field;
            $.ajax({
                type: "post",
                url: "/member/update",
                data: data2Send,
                async: false,
                dataType: "json",
                success: function(res){
                    var msg = "";
                    console.log(res.message);
                    if (res.message === 'SUCCESS') {
                        msg = '修改成功!窗口关闭';
                    } else {
                        msg = '修改失败!窗口关闭'
                    }
                    parentLayer.msg(msg, {
                        icon: 1,
                        time: 1000
                    }, function () {
                        parentLayer.close(thisIndex);
                        pWindow.document.getElementById('searchBtn').click();
                    });
                }
            });
        });
    });

</script>

</body>